try
{
    Ext.Loader.setConfig(
    {
        enabled : true
    });

    Ext.Loader.setPath(
    {
        'Util' : 'app/util',
        'Security' : 'app'
    });
    Ext.application(
    {
        name : 'Security',

        appFolder : 'app',

        requires :
        [
            'Util.Functions',
            'Util.AccountHelper',
            'Util.UserManager',
            'Util.SessionManager'
        ],

        controllers :
        [
            'CoreController'
        ],

        setPageTitle : function(title)
        {
            document.title = 'Login : ' + title;
        },

        launch : function()
        {
            Ext.Ajax.on('requestexception', this.onRequestException, this);
            Security.viewport = null;

            window.runtime = {};
            window.runtime.textFieldLength = 300;

            this.buildViewport();

//            $(window).unbind("resizeEnd");
//            $(window).resize(function()
//            {
//                if (this.resizeTO)
//                    clearTimeout(this.resizeTO);
//                this.resizeTO = setTimeout(function()
//                {
//                    $(this).trigger('resizeEnd');
//                }, 100);
//            });
        },

        buildViewport : function()
        {

            Security.viewport = Ext.create('Ext.container.Viewport',
            {
                id : 'bpm-root-viewport',
                layout : 'fit',
                border : false,
                items :
                [
                    {
                        id : 'bpm-scroll-container',
                        layout : 'border',
                        overflowX : 'false',
                        overflowY : 'false',
                        border : false,
                        items :
                        [
                            {
                                id : 'LoginPage',
                                xtype : 'loginpage',
                                region : 'center',
                                flex : 1,
                                border : false
                            }
                        ]
                    }
                ]
            });
        },

        onRequestException : function(conn, response, options)
        {
            if (response.status == 505)
            {
                Ext.Msg.show(
                {
                    title : 'Internal Server Error',
                    msg : 'HTTP Version Not supported.',
                    buttons : Ext.Msg.OK,
                    icon : Ext.Msg.ERROR,
                    closable : false,
                    modal : true,
                    draggable : false
                });
            } else if (response.status == 403)
            {
                Ext.Msg.show(
                {
                    title : 'Access Denied',
                    msg : 'Your session expired. You will be redirected to the login page.',
                    buttons : Ext.Msg.OKCANCEL,
                    icon : Ext.Msg.WARNING,
                    closable : false,
                    modal : true,
                    draggable : false,
                    fn : function(btn)
                    {
                        if (btn == 'ok')
                        {
                            if (SecurityConfig.integration.SESSION_TIMEOUT_URL)
                            {
                                var contextPathLength = SecurityConfig.integration.CONTEXT_PATH.length;
                                var relativePath = document.location.pathname.substring(contextPathLength);
                                var relativeUrl = relativePath + document.location.hash;
                                window.location = SecurityConfig.integration.SESSION_TIMEOUT_URL + '?' + Ext.urlEncode(
                                {
                                    url : relativeUrl
                                });
                                //url=%2Fsecurity%2Findex.html%23%21%2Froles';
                            } else
                            {
                                window.location.reload();
                            }
                        } else
                            return;
                    }
                });
            } else if (response.status == 500)
            {
                Ext.Msg.show(
                {
                    title : 'Internal Server Error',
                    msg : 'A FATAL internal error occurred.<br>Please contact the Site Administrator for assistance.',
                    buttons : Ext.Msg.OK,
                    icon : Ext.Msg.ERROR,
                    closable : false,
                    modal : true,
                    draggable : false
                });
            }
            //handle other error statuses
        }

    });
} catch (err)
{

}
